using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace bowlingkata
{
    partial class Frame
    {
        public static IEnumerable<Frame> CreateFramesFromRolls(IEnumerable<int> rolls)
        {
            Frame frame = null;
            foreach (var roll in rolls)
            {
                if (frame == null) frame = new Frame();

                frame.AddRoll(roll);

                if (frame.IsFull)
                {
                    yield return frame;
                    frame = null;
                }
            }
            if (frame != null) yield return frame;
        }
    }
}